home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / misc / sana2.lha / sana2 / examples / skeleton / skeleton.c next >
Encoding:
C/C++ Source or Header  |  1991-11-18  |  1.4 KB  |  80 lines

  1. /*
  2. **  $Id: skeleton.c,v 1.2 91/11/08 10:47:58 dlarson Exp $
  3. **
  4. **  SANA-II driver utility skeleton functions.
  5. **
  6. **  Copyright 1991 Commodore-Amiga, Inc.
  7. **
  8. **  This code may be modified and used freely on Amiga computers.
  9. **
  10. */
  11.  
  12.  
  13. #include "skeleton.h"
  14.  
  15. int initdev(void)
  16. {
  17. char device[80];
  18. char buff[80];
  19. LONG unit;
  20. struct TagItem MyTags[2];
  21.  
  22.     printf("Device name to open:  ");
  23.     if(GetVar("SANA2.Device", device, 80, 0) == -1)
  24.         scanf("%s", device);
  25.     else
  26.         printf("%s\n", device);
  27.     printf("Unit number to open:  ");
  28.     if(GetVar("SANA2.Unit", buff, 80, 0) == -1)
  29.         scanf("%d", &unit);
  30.     else
  31.     {
  32.         sscanf(buff, "%ld", &unit);
  33.         printf("%ld\n", unit);
  34.     }
  35.     printf("\n");
  36.  
  37.     if ( !(DevPort = CreateMsgPort()) )
  38.     {
  39.         printf("Could not allocate port.\n");
  40.         return(0);
  41.     }
  42.  
  43.     if (!(IOB1 = CreateIORequest(DevPort, sizeof(struct IOSana2Req))))
  44.     {
  45.         printf("Could not allocate extio block.\n");
  46.         return(0);
  47.     }
  48.  
  49.     MyTags[0].ti_Tag = S2_CopyToBuff;
  50.     MyTags[0].ti_Data = (ULONG) CopyToBuff;
  51.     MyTags[1].ti_Tag = S2_CopyFromBuff;
  52.     MyTags[1].ti_Data = (ULONG) CopyFromBuff;
  53.     IOB1->ios2_BufferManagement = MyTags;
  54.  
  55.     if (OpenDevice(device, unit, IOB1, 0))
  56.     {
  57.         printf("Could not open device.\n");
  58.         return(0);
  59.     }
  60.  
  61.     DeviceOpen = 1;
  62.     DevBits = 1L << DevPort->mp_SigBit;
  63.     return(1);
  64. }
  65.  
  66.  
  67. void closedev(void)
  68. {
  69.     if(DeviceOpen)
  70.     {
  71.         printf("\nAttempting To Close Unit.\n");
  72.         CloseDevice(IOB1);
  73.         printf("Closed.\n");
  74.     }
  75.     if(IOB1)
  76.         DeleteIORequest(IOB1);
  77.     if(DevPort)
  78.         DeleteMsgPort(DevPort);
  79. }
  80.